package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.domain.SysApp;
import com.ruoyi.system.service.ISysAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "App")
@RestController
@RequestMapping("/app")
public class SysAppController extends BaseController {
    @Autowired
    private ISysAppService SysAppService;

    /**
     * 查询App列表
     */
    // @RequiresPermissions("system:app:list")
    @GetMapping("/list")
    @ApiOperation(value = "App列表（分页）", response = SysApp.class)
    public TableDataInfo list(SysApp sysApp) {
        startPage();
        List<SysApp> list = SysAppService.selectSysAppList(sysApp);
        return getDataTable(list);
    }

    /**
     * 查询App列表
     */
    // @RequiresPermissions("system:app:list")
    @GetMapping("/appList")
    @ApiOperation(value = "App列表", response = SysApp.class)
    public AjaxResult appList(SysApp sysApp) {
        List<SysApp> list = SysAppService.selectSysAppList(sysApp);
        return success(list);
    }


    /**
     * 导出App列表
     */
    // @RequiresPermissions("system:app:export")
    @Log(title = "App", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出App列表")
    public void export(HttpServletResponse response, SysApp SysApp) {
        List<SysApp> list = SysAppService.selectSysAppList(SysApp);
        ExcelUtil<SysApp> util = new ExcelUtil<SysApp>(SysApp.class);
        util.exportExcel(response, list, "App数据");
    }

    /**
     * 获取App详细信息
     */
    // @RequiresPermissions("system:app:query")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取App详细信息", response = SysApp.class)
    public AjaxResult getInfo(@ApiParam(value = "id", required = true) @PathVariable("id") Long id) {
        return success(SysAppService.selectSysAppById(id));
    }

    /**
     * 新增App
     */
    // @RequiresPermissions("system:app:add")
    @Log(title = "新增App", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增App")
    public AjaxResult add(@RequestBody SysApp SysApp) {
        return toAjax(SysAppService.insertSysApp(SysApp));
    }

    /**
     * 修改App
     */
    // @RequiresPermissions("system:app:edit")
    @Log(title = "修改App", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改App")
    public AjaxResult edit(@RequestBody SysApp SysApp) {
        return toAjax(SysAppService.updateSysApp(SysApp));
    }

    /**
     * 删除App
     */
    // @RequiresPermissions("system:app:remove")
    @Log(title = "删除App", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    @ApiOperation(value = "删除App")
    public AjaxResult remove(@ApiParam(value = "id", required = true) @PathVariable Long[] ids) {
        return toAjax(SysAppService.deleteSysAppByIds(ids));
    }
}
